/*
** my_getnbr.c for my_getnbr in /home/goupil_r//afs/local/Jour_04
** 
** Made by robin goupil
** Login   <goupil_r@epitech.net>
** 
** Started on  Thu Oct  4 15:05:21 2012 robin goupil
** Last update Thu Oct  4 19:21:14 2012 robin goupil
*/

int	my_readnbr(char *str)
{
  int	out;
  int	result;

  out = 0;
  while ((*str <= 57 && *str >= 48) && *str != '\0')
    {
      result = out * 10 + (*str - 48);
      if ((out < 0 && result > 0) || (out > 0 && result < 0))
	{
	  return 0;
	}
      out = out * 10 + (*str - 48);
      str = str + 1;
    }
  return out;
}

int	my_getnbr(char *str)
{
  int	sign;
  char *start;

  sign = 1;
  start = str;
  while ((*str < 48 || *str > 57) && *str != '\0')
    {
      if (*str == '-')
	sign = sign * (-1);
      str = str + 1;
    }
  if (start < str && *(str - 1) == '-')
    {
      sign = -1;
    }
  return my_readnbr(str) * sign;
}
